#include<bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int n;
int a[N], backup[N];//backup备份 

int get(int k)
{
    int sum = 0, cnt = 1;
    memcpy(a, backup, sizeof a);
    while(true)
    { 
        while(a[k] == 0)
            k = (k + 1) % n;//回到起始位置 
        if(a[k] == cnt)
        {
            sum += a[k];//拿走 
            a[k] = 0;//标记 
            cnt = 1;//重新开始 
        }
        else
            cnt ++;
        
        k = (k + 1) % n;//不管数找没找到都向后走一位 
        if(*max_element(a, a + n) == 0)
            return sum;
        if(cnt > n)
            return sum;
    }
    return -1;
}

int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> backup[i];
    
    int res = 0;
    for(int i=0; i<n; i++)
        res = max(res, get(i));
    
    cout << res << endl;
    return 0;
}